package com.shiningstars.tools;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.shiningstars.R;
import com.shiningstars.general.Constants;
import com.shiningstars.general.Messages;
import com.shiningstars.valuebeans.Feedback;

public class FeedbackAdapter extends ArrayAdapter<Feedback> implements Constants, Messages {

	private final Context context;
	private final List<Feedback> feedbackHistoryList;

	public FeedbackAdapter(Context ctx, List<Feedback> list) {
		super(ctx, R.layout.feedback_history_layout, list);
		context = ctx;
		feedbackHistoryList = list;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.feedback_history_layout, parent, false);
		TextView textView = (TextView) rowView.findViewById(R.id.label);
		ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
		ProgressBar progressBar = (ProgressBar) rowView.findViewById(R.id.progress);

		if (position == 0) {
			textView.setText(CLICK_NEW_FEEDBACK);
			imageView.setImageResource(R.drawable.plus);
			textView.setTextColor(Color.parseColor(GREY));
			progressBar.setVisibility(ProgressBar.GONE);
		} else {
			Feedback feedback = feedbackHistoryList.get(position);
			textView.setText(feedback.getQuestion3());
			if (feedback.getIsNotified().equals(Y)) {
				imageView.setImageResource(R.drawable.tick);
				progressBar.setVisibility(ProgressBar.GONE);
			}
		}

		return rowView;
	}
}